package spaceinvaders;

import javax.swing.ImageIcon;


public class Alien extends Sprite {

	private Bomb bomb;
	private final String alien1 = "spacepix/alien1.png",
			alien1_2 = "spacepix/alien1_2.png",
			alien2 = "spacepix/alien2.png",
			alien2_2 = "spacepix/alien2_2.png",
			alien3 = "spacepix/alien3.png",
			alien3_2 = "spacepix/alien3_2.png";
	private ImageIcon alienImage1, alienImage1_2,
	alienImage2, alienImage2_2, alienImage3, alienImage3_2;
	private int width, height;

	public Alien(int x, int y, int s, int c) {
		this.x = x;
		this.y = y;

		bomb = new Bomb(x, y, s, c);
		alienImage1 = new ImageIcon(alien1);
		alienImage1_2 = new ImageIcon(alien1_2);
		alienImage2 = new ImageIcon(alien2);
		alienImage2_2 = new ImageIcon(alien2_2);
		alienImage3 = new ImageIcon(alien3);
		alienImage3_2 = new ImageIcon(alien3_2);
		if (s==1) {
			setImage(alienImage1.getImage());
			this.origImage = alienImage1.getImage();
		}
		else if (s==2||s==3) {
			setImage(alienImage2.getImage());
			this.origImage = alienImage2.getImage();
		}
		else {
			setImage(alienImage3.getImage());
			this.origImage = alienImage3.getImage();
		}
		
		// you had this previously, but I don't know why
		// if its necessary change it back
		//width = getImage().getWidth(null)+5;
		//height = getImage().getHeight(null)+5;
		width = getImage().getWidth(null);
		height = getImage().getHeight(null);
	}

	public void act(int direction) {
		if(SpaceInvaders.getLevel()<=3){
		this.x += direction;
		}
		else{
				this.y+=Game.directionY.get(direction);
				this.x+=Game.directionX.get(direction);
		}
		
	}
	
	public int getWidth() {
		return width;
	}
	
	public int getHeight() {
		return height;
	}

	public Bomb getBomb() {
		return bomb;
	}
	
	public void toggleImage() {
		if (getImage().equals(alienImage1.getImage()))
			setImage(alienImage1_2.getImage());
		else if (getImage().equals(alienImage1_2.getImage()))
			setImage(alienImage1.getImage());
		if (getImage().equals(alienImage2.getImage()))
			setImage(alienImage2_2.getImage());
		else if (getImage().equals(alienImage2_2.getImage()))
			setImage(alienImage2.getImage());
		if (getImage().equals(alienImage3.getImage()))
			setImage(alienImage3_2.getImage());
		else if (getImage().equals(alienImage3_2.getImage()))
			setImage(alienImage3.getImage());
	}

	public class Bomb extends Sprite {

		private String bomb = "spacepix/bomb1.png",
				bomb2 = "spacepix/bomb2.png";
		private final int H_SPACE = 26;
		private final int V_SPACE = 25;
		private int speed, caliber;
		private boolean destroyed = true;
		private ImageIcon bombImage, bombImage2;

		public Bomb() {
		}

		public Bomb(int x, int y, int s, int c) {

			bombImage = new ImageIcon(bomb);
			setImage(bombImage.getImage());
			bombImage2 = new ImageIcon(bomb2);
			setX(x + H_SPACE);
			setY(y - V_SPACE);
			speed=s;
			caliber=c;
		}

		int getSpeed(){
			return speed;
		}

		int getCaliber(){
			return caliber;
		}

		public void setDestroyed(boolean destroyed) {
			this.destroyed = destroyed;
		}

		public boolean isDestroyed() {
			return destroyed;
		}
		
		public void setCaliber(int inCaliber){
				caliber = inCaliber;
		}
		
		public void toggleImage() {
			if (getBomb().getImage().equals(bombImage.getImage()))
				getBomb().setImage(bombImage2.getImage());
			else
				getBomb().setImage(bombImage.getImage());
		}

	}
}